#include <iostream>

struct Node {
    int data;
    Node* next;
};

class SinglyLinkedList {
private:
    Node* head;

public:
    SinglyLinkedList() : head(nullptr) {}

    ~SinglyLinkedList() {
        Node* current = head;
        while (current != nullptr) {
            Node* next = current->next;
            delete current;
            current = next;
        }
    }

    // Добавление элемента в начало
    void addFront(int value) {
        Node* newNode = new Node{value, head};
        head = newNode;
    }

    // Добавление элемента в конец
    void addBack(int value) {
        Node* newNode = new Node{value, nullptr};
        if (head == nullptr) {
            head = newNode;
        } else {
            Node* current = head;
            while (current->next != nullptr) {
                current = current->next;
            }
            current->next = newNode;
        }
    }

    // Удаление элемента по значению
    bool remove(int value) {
        Node* current = head;
        Node* previous = nullptr;
        while (current != nullptr && current->data != value) {
            previous = current;
            current = current->next;
        }
        if (current == nullptr) return false;
        if (previous == nullptr) {
            head = current->next;
        } else {
            previous->next = current->next;
        }
        delete current;
        return true;
    }

    // Поиск элемента
    bool search(int value) const {
        Node* current = head;
        while (current != nullptr) {
            if (current->data == value) return true;
            current = current->next;
        }
        return false;
    }

    // Вывод списка
    void print() const {
        Node* current = head;
        while (current != nullptr) {
            std::cout << current->data << " -> ";
            current = current->next;
        }
        std::cout << "nullptr" << std::endl;
    }
};

int main() {
    SinglyLinkedList list;
    list.addFront(10);
    list.addFront(20);
    list.addBack(30);
    list.print(); // 20 -> 10 -> 30 -> nullptr

    list.remove(10);
    list.print(); // 20 -> 30 -> nullptr

    std::cout << "Содержит 30: " << list.search(30) << std::endl; // 1
    std::cout << "Содержит 10: " << list.search(10) << std::endl; // 0

    return 0;
}
